From 3aeacff4e3fe2cfbfaa6e22e9c8f5dcaa09c0878 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Thu, 15 Jun 2017 16:48:05 +0200 Subject: [PATCH] hash '__CARGO_DEFAULT_LIB_METADATA' in metadata for rustc This will let us seed the release channel as part of the metadata used for the hash to avoid conflicting hashes across channels. Signed-off-by: Marc-Antoine Perennou --- src/cargo/ops/cargo_rustc/context.rs | 11 +++++++++-- tests/build.rs | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index fa1ddd004..b185a2ed3 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -442,16 +442,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> { // Note, though, that the compiler's build system at least wants // path dependencies (eg libstd) to have hashes in filenames. To account for // that we have an extra hack here which reads the - // `__CARGO_DEFAULT_METADATA` environment variable and creates a + // `__CARGO_DEFAULT_LIB_METADATA` environment variable and creates a // hash in the filename if that's present. // // This environment variable should not be relied on! It's // just here for rustbuild. We need a more principled method // doing this eventually. + let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA"); if !unit.profile.test && (unit.target.is_dylib() || unit.target.is_cdylib()) && unit.pkg.package_id().source_id().is_path() && - !env::var("__CARGO_DEFAULT_LIB_METADATA").is_ok() { + !__cargo_default_lib_metadata.is_ok() { return None; } @@ -491,6 +492,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> { rustc.verbose_version.hash(&mut hasher); } + // Seed the contents of __CARGO_DEFAULT_LIB_METADATA to the hasher if present. + // This should be the release channel, to get a different hash for each channel. + if let Ok(ref channel) = __cargo_default_lib_metadata { + channel.hash(&mut hasher); + } + Some(Metadata(hasher.finish())) } diff --git a/tests/build.rs b/tests/build.rs index 0d533b406..a5293b314 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -849,7 +849,7 @@ suffix = env::consts::DLL_SUFFIX, assert_that(p.cargo("clean"), execs().with_status(0)); // If you set the env-var, then we expect metadata on libbar - assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "1"), + assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "stable"), execs().with_status(0).with_stderr(&format!("\ [COMPILING] bar v0.0.1 ({url}/bar) [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \ -- 2.30.2